<?php
namespace Api\SA;


class Otp {

    /**
     * otp验证方法
     *
     * @param string $username 用户名
     * @param string $code     校验码
     *
     * @return bool
     * @throws \Base\Exception\Service
     */
    public function verify($username, $code) {
        $data = array(
            'username' => $username,
            'code'     => $code,
            'app'      => APP_NAME,
            'ip'       => \S\Util\Ip::getClientIp(),
        );

        $util = new Util();
        $ret  = $util->request("api/otp/check", $data);
        if ($ret === false) {
            $code    = $util->getCode();
            $message = $util->getMessage();
            throw new \Base\Exception\Service($message, $code);
        } else {
            return true;
        }
    }

}